<?php


namespace App\Admin\Controllers;


use App\Models\ProductModel;
use App\Models\ProductNameModel;
use App\Models\ReportModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;

class ReportController extends AdminController
{

    use HasResourceActions;

    protected $title = '投诉';

    public function index(Content $content)
    {
        return $content
            ->header('投诉管理')
            ->description(trans('admin.list'))
            ->body($this->grid()->render());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ReportModel());

        $grid->column('report_id', '投诉ID');
        $grid->column('reason', '理由');
        $grid->column('created_at', '时间');
        $grid->column('code', '溯源码');
        $grid->column('phone', '投诉人联系方式');
        $grid->column('ip', '投诉人IP地址');
        $grid->column('ProductBatch', '商品')->display(function($value,$data){
            return $this->ProductBatch['product']['product_name'];
        });

        $grid->disableActions();
        $grid->disableCreateButton();

//禁用分页条
//
//$grid->disablePagination();
//
//禁用查询过滤器
//
//$grid->disableFilter();
//
//禁用导出数据按钮
//
//$grid->disableExport();
//
//禁用行操作列
//
//$grid->disableActions();

        $grid->filter(function ($filter) {
//            $filter->column(1 / 2, function ($filter) {
//                $filter->where(function ($query) {
//                    $query->where('product.product_name', 'like', "%{$this->input}%");
//                }, '关键词')->placeholder('产品名');
//            });

            $filter->column(1 / 2, function ($filter) {
                $filter->where(function ($query) {
                    $query->where('code', '=', $this->input);
                }, '溯源码')->placeholder('溯源码');
            });

            $filter->column(1 / 2, function ($filter) {
                $filter->where(function ($query) {
                    $query->where('ip', '=', $this->input);
                }, 'IP地址')->placeholder('IP地址');
            });
        });


        return $grid;
    }
}
